#include "D:\sky\MPLAB IDE PROJECTS\Standard Projects\Header_xc8.h"

void EE_WRT(void);
unsigned char EE_READ(void);
unsigned char EE_READ(void)
{
	EECON1bits.EEPGD = 0;
	EECON1bits.CFGS = 0;
	EECON1bits.RD = 1;
	return(EEDATA);
}
void main(void)
{
	unsigned char x;
	TRISB = 0x00;
	TRISD = 0x00;
	ADCON1 = 0x0F;
	//write to EEPROM
	EEADR = 0x0; //EEPROM location
	EEDATA = 'Y';//write this character to it
	EE_WRT();
	EEADR = 0x1;
	EEDATA = 'A';
	EE_WRT();
	EEADR = 0x2;
	EEDATA = 'P';
	EE_WRT();
	EECON1bits.WREN = 0; //diable WRITE
	//read from EEPROM and place it on PORTB
	EECON1bits.RD = 1;
	EEADR = 0x0;
	x = EE_READ();
	PORTD = x;
	__delay_ms(15);
	EEADR = 0x1;
	x = EE_READ();
	PORTD = x;
	__delay_ms(15);
	EEADR = 0x2;
	x = EE_READ();
	PORTD = x;
	__delay_ms(15);
	while(1);
}

void EE_WRT()
{
	EECON1bits.EEPGD = 0;
	EECON1bits.CFGS = 0;
	EECON1bits.WREN = 1;
	INTCONbits.GIE = 0;
	EECON2 = 0X55;
	EECON2 = 0XAA;
	EECON1bits.WR = 1;
	INTCONbits.GIE = 1;
	while(!PIR2bits.EEIF);
	PIR2bits.EEIF = 0;
	
}
